/**
  ******************************************************************************
  * @file           : raster_if.h
  * @version        : v1.0
  * @brief          : Header for raster_if.c file.
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __RASTER_IF_H__
#define __RASTER_IF_H__

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "usbd_cdc.h"

/* USER CODE BEGIN INCLUDE */

// word
typedef struct {
    uint8_t  byteH;
    uint8_t  byteL;
} net_w;
/* USER CODE END INCLUDE */

/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
  * @brief For Usb device.
  * @{
  */

/** @defgroup USBD_CDC_IF USBD_CDC_IF
  * @brief Usb VCP device module
  * @{
  */

/** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines
  * @brief Defines.
  * @{
  */
/* USER CODE END EXPORTED_DEFINES */

/**
  * @}
  */

/** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types
  * @brief Types.
  * @{
  */

/* USER CODE BEGIN EXPORTED_TYPES */
typedef struct {
  uint8_t cmd;
  uint8_t len;  // para length without cmd
  uint8_t code;
  uint16_t (* cmdUsrHandle)(const uint8_t *pbuf, uint16_t len);
}POS_CMD_DEF;

//GS v 0 m xL xH yL yH d1...dk
typedef struct {
  uint8_t cmd;
  uint8_t code;
  uint8_t fix;
  uint8_t m;
  uint8_t xL;
  uint8_t xH;
  uint8_t yL;
  uint8_t yH;
}GS_V_PRINT_IMG_HEADER;

// ESC & y c1 c2 [x1 d1 ... d(y × x1)] ... [xk d1 ... d(y × xk)] Define download characters
typedef struct {
  uint8_t cmd;
  uint8_t code;
  uint8_t y;
  uint8_t c1;
  uint8_t c2;
  uint8_t data[0];
}ESC_DL_CHAR_SET_HEADER;

// ESC * m nL nH d1...dk Specify bit image mode
typedef struct {
  uint8_t cmd;
  uint8_t code;
  uint8_t m;
  uint8_t nL;
  uint8_t nH;
  uint8_t data[0];
}ESC_BIT_IMG_MODE_HEADER;

typedef struct {
  net_w x;
  net_w y;
  net_w bdlen;
  uint8_t data[65536];
}PIC_FILE_t;
/* USER CODE END EXPORTED_TYPES */

/**
  * @}
  */

/** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros
  * @brief Aliases.
  * @{
  */

/* USER CODE BEGIN EXPORTED_MACRO */
// 短整型大小端互换
#define BigLittleSwap16(A)  ((((uint16_t)(A) & 0xff00) >> 8) | \
                             (((uint16_t)(A) & 0x00ff) << 8))

#define GetBit(dat,i) (((dat)&((uint32_t)1<<(i)))?1:0)
#define GetMaskBit(dat,mask) (((dat)&((uint32_t)mask))?1:0)
#define SetBit(dat,i) ((dat)|=((uint32_t)1<<(i)))
#define ClearBit(dat,i) ((dat)&=(~((uint32_t)0x01<<(i))))
#define ClearNBit(dat,i) ((dat)&=((uint32_t)0x01<<(i)))
#define AssignBit(dat,i,value) ((value)? SetBit(dat,i):ClearBit(dat,i))
#define AssignMask(dat,mask,value) ((dat) = (((dat) & ~(mask)) | ((value) & (mask))))
#define InverseBit(dat, i) (AssignBit(dat, i, GetBit(dat, i)))
/* USER CODE END EXPORTED_MACRO */

/**
  * @}
  */

/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables
  * @brief Public variables.
  * @{
  */

/* USER CODE BEGIN EXPORTED_VARIABLES */

/* USER CODE END EXPORTED_VARIABLES */

/**
  * @}
  */

/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype
  * @brief Public functions declaration.
  * @{
  */


/* USER CODE BEGIN EXPORTED_FUNCTIONS */
uint16_t GetDlCharSet(const uint8_t *pbuf, uint16_t len);
uint16_t GetBitImageMode(const uint8_t *pbuf, uint16_t len);
uint16_t SetHorTab(const uint8_t *pbuf, uint16_t len);
uint16_t GetRaster(const uint8_t *pbuf, uint16_t len);

/* USER CODE END EXPORTED_FUNCTIONS */

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __USBD_CDC_IF_H__ */

